//
//  SegmentCell.m
//  League
//
//  Created by JackChen on 2018/2/19.
//  Copyright © 2018年 ciyuanjuzhen. All rights reserved.
//

#import "SegmentCell.h"

@implementation SegmentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.stateSegment addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
}

- (void)bindViewWithTitle:(NSString *)title segmentState:(NSArray *)segment {
    self.titleLabel.text = title;
    for (int i=0; i<2; i++) {
        [self.stateSegment setTitle:segment[i] forSegmentAtIndex:i];
    }
    if (self.state == ProferenceSexState) {
        if (self.stateSegment.numberOfSegments == 2) {
            [self.stateSegment insertSegmentWithTitle:segment[2] atIndex:2 animated:NO];
        }
    }
}

-(void)change:(UISegmentedControl *)sender {
    ProfileManager *manager = [ProfileManager shareManager];
    if (self.state == ProfileSexState) {
        manager.sex = sender.selectedSegmentIndex;
    }
    if (self.state == ProfileSigleState) {
        manager.single = sender.selectedSegmentIndex;
    }
    if (self.state == ProferenceSexState) {
        manager.lookfor = sender.selectedSegmentIndex;
    }
}
@end
